package gobatch

// Task is a function type for doing work in a simple step
type Task func(execution *StepExecution) BatchError

// Handler is a interface for doing work in a simple step
type Handler interface {
	//Handle implement handler logic here
	Handle(execution *StepExecution) BatchError
}

// Reader is for loading data in a chunk step
type Reader interface {
	//Read each call of Read() will return a data item, if there is no more data, a nil item will be returned.
	//If there is an error, nil item and a BatchError will return
	Read(chunkCtx *ChunkContext) (interface{}, BatchError)
}

// Processor is for processing data in a chunk step
type Processor interface {
	//Process process an item from reader and return a result item
	Process(item interface{}, chunkCtx *ChunkContext) (interface{}, BatchError)
}

// Writer is for writing data in a chunk step
type Writer interface {
	//Write write items generated by processor in a chunk
	Write(items []interface{}, chunkCtx *ChunkContext) BatchError
}

// OpenCloser is used doing initialization and cleanups for Reader or Writer
type OpenCloser interface {
	//Open do initialization for Reader or Writer
	Open(execution *StepExecution) BatchError
	//Close do cleanups for Reader or Writer
	Close(execution *StepExecution) BatchError
}

// Partitioner split an execution of step into multiple sub executions.
type Partitioner interface {
	//Partition generate sub step executions from specified step execution and partitions count
	Partition(execution *StepExecution, partitions uint) ([]*StepExecution, BatchError)
	//GetPartitionNames generate sub step names from specified step execution and partitions count
	GetPartitionNames(execution *StepExecution, partitions uint) []string
}

// PartitionerFactory can create Partitioners, it is used by Reader usually.
type PartitionerFactory interface {
	GetPartitioner(minPartitionSize, maxPartitionSize uint) Partitioner
}

// Aggregator merge results of sub step executions of a chunk step
type Aggregator interface {
	//Aggregate aggregate result from all sub step executions
	Aggregate(execution *StepExecution, subExecutions []*StepExecution) BatchError
}
